<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2024/8/15
  Time: 14:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <form>
        用户名<input type="text" name="name" id="nameId"><span id="nameSpan"></span><br>
        密码<input type="text" name="password" id="passwordId"><br>
        <input type="submit" value="登录">
    </form>

    <script src="/static/jquery-2.1.4.js" type="text/javascript" charset="UTF-8"></script>
    <script>
        $(function () {
           $("#nameId").blur(function () {
               $.post(
                   '/ajax2',
                   {'name':$(this).val()},
                   function (jsonObj) {
                       console.log(jsonObj);
                       if(jsonObj.exist) {
                           $('#nameSpan').html(jsonObj.msg);
                           $('#nameSpan').css('color','red');
                       } else {
                           $('#nameSpan').html(jsonObj.msg);
                           $('#nameSpan').css('color','green');
                       }
                   },
                   'json'
               );
           });
        })
    </script>
</body>
</html>
